package com.atguigu.gmall.mq.receiver;

import com.atguigu.gmall.mq.config.DeadLetterMqConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

@Component
public class DeadLetterMessage {

    //基于死信延迟消息
    @RabbitListener(queues = DeadLetterMqConfig.queue_dead_2)
    public void message(String msg, Message message, Channel channel){
        try {
            System.out.println("收到的消息 " + msg);
            System.out.println("收到的消息时间 " + new Date());
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
